class Solution {
public:
    vector<int> intersect(vector<int>& nums1, vector<int>& nums2)
    {
        vector<int> ans;
        unordered_map<int, int> mp;
        for (auto e : nums1) mp[e]++;
        for (auto e : nums2)
        {
            if (mp[e] > 0)
            {
                mp[e]--;
                ans.push_back(e);
            }
        }
        return ans;
    }
};